﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyEncoder
{
    public class MyEncode
    {
        /// <summary>
        /// 明文
        /// </summary>
        public string PlainText { get; set; }
        /// <summary>
        /// 密文
        /// </summary>
        public string CipherText { get; set; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 加密动作
        /// </summary>
        public void Encode()
        {
            //加密过程
            for (int i = 0, j = 0; i < PlainText.Length; i++, j++)
            {
                if (j % Key.Length == 0)
                    j = 0;
                int number = (CharToNo(PlainText[i]) + CharToNo(Key[j])) % 26;
                CipherText += Convert.ToChar(number + 'a');
            }
        }
        private int CharToNo(char ch)
        {
            return ch - 'a';
        }
    }
}
